<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function ranCode(){
            var str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", sCode = "";
            for(var i = 0; i < 4; i++){
                sCode += str.charAt(Math.floor(Math.random() * 62));
            }
            return sCode;
        }
        console.log(ranCode());
    </script>
</head>
<body>

</body>
</html>